import 'package:todo_app/constants/Screen.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';

class CustomTextInput extends StatelessWidget {
  final TextEditingController? controller;
  final String? placeholder;
  final Pattern? rule;
  final TextStyle? style;
  final TextStyle? placeholderStyle;
  final TextInputType? keyboardType;
  final TextInputAction? textInputAction;
  final bool obscureText;
  final List<TextInputFormatter>? inputFormatters;
  final double? height;
  final double? width;
  final int? maxLength;
  final int? maxLines;
  final FocusNode? focusNode;
  final TextAlign? textAlign;
  final BoxDecoration? decoration;
  final ValueChanged<String>? onChanged;
  final EdgeInsetsGeometry? padding;
  final EdgeInsetsGeometry? margin;

  const CustomTextInput({Key? key, this.margin, this.controller,this.maxLines, this.placeholder, this.rule, this.placeholderStyle, this.style, this.keyboardType, this.textInputAction, this.inputFormatters, this.obscureText = false, this.height, this.maxLength, this.focusNode, this.textAlign, this.decoration,this.onChanged, this.width, this.padding }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    
    final formatters = <TextInputFormatter>[];
    if(rule != null) {
      formatters.add(
        FilteringTextInputFormatter.allow(rule!),
      );
    }
    if(inputFormatters != null) formatters.addAll(inputFormatters!);

    return Container(
      height: height,
      width: width,
      margin: margin,
      child: CupertinoTextField(
        controller: controller,
        placeholder: placeholder,
        placeholderStyle: TextStyle(height: 1.2, color: const Color(0xFFA0A0A0), fontSize: Screen.sizeByDesign(14)).merge(style).merge(placeholderStyle),
        decoration:decoration??const BoxDecoration(),
        inputFormatters: formatters,
        style: TextStyle(height: 1.2, fontSize: Screen.sizeByDesign(14)).merge(style),
        keyboardType: keyboardType,
        onChanged: onChanged??(v){},
        textInputAction: textInputAction,
        obscureText: obscureText,
        padding: padding ?? EdgeInsets.zero,
        maxLength: maxLength,
        maxLines: maxLines,
        focusNode: focusNode,
        textAlign: textAlign ?? TextAlign.start,
      )
    );
  }
}